package org.jeecg.modules.zcgl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.zcgl.entity.RegionUser;
import org.jeecg.modules.zcgl.mapper.RegionUserMapper;
import org.jeecg.modules.zcgl.service.IRegionUserService;
import org.jeecg.modules.zcgl.vo.RegionUserVo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 区域管理员信息
 * @Author: jeecg-boot
 * @Date:   2020-08-11
 * @Version: V1.0
 */
@Service
public class RegionUserServiceImpl extends ServiceImpl<RegionUserMapper, RegionUser> implements IRegionUserService {

    @Override
    public boolean addList(RegionUserVo vo) {
        if (vo == null || vo.getUserIdList() == null || StringUtils.isBlank(vo.getRegionId())){
            return false;
        }
        for (String userId : vo.getUserIdList()){
            LambdaQueryWrapper<RegionUser> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(RegionUser::getRegionId, vo.getRegionId());
            queryWrapper.eq(RegionUser::getUserId, userId);
            RegionUser check = baseMapper.selectOne(queryWrapper);
            if (check == null){
                check = new RegionUser(userId, vo.getRegionId());
                baseMapper.insert(check);
            }
        }
        return true;
    }

    @Override
    public List<String> queryUserIdListByRegionId(String regionId) {
        return baseMapper.queryUserIdListByRegionId(regionId);
    }
}
